package org.dromara.business.utils;

import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

public final class FileUtil extends cn.hutool.core.io.FileUtil {


    /**
     * 获取文件后缀
     *
     * @param fileName 文件名
     * @return boolean
     */
    public static String getFileExtension(String fileName) {
        return fileName.substring(fileName.lastIndexOf(".") + 1);
    }

    /**
     * 判断文件是否图片类型
     *
     * @param fileName 文件名
     * @return boolean
     */
    public static boolean isImage(String fileName) {
        String extension = getFileExtension(fileName);
        String[] imageExtension = new String[]{"jpeg", "jpg", "bmp", "png", "webp", "gif"};
        for (String e : imageExtension) {
            if (extension.toLowerCase().equals(e)) {
                return true;
            }
        }

        return false;
    }

    /**
     * 判断文件是否视频类型
     *
     * @param fileName 文件名
     * @return boolean
     */
    public static boolean isVideo(String fileName) {
        String extension = getFileExtension(fileName);
        String[] videoExtension = new String[]{"mp4","flv","avi","rmvb","wmv","mpeg","divx","vob"};
        for (String e : videoExtension) {
            if (extension.toLowerCase().equals(e)) {
                return true;
            }
        }

        return false;
    }

    public static String randomFileName(String extName){
        return IdUtil.fastUUID() + RandomUtil.randomString(10) + "." + extName;
    }

    public static void main(String[] args) {
//        String aa = "D:\\work\\01-im\\im\\上货说明.png";
//        System.out.println(getMimeType(aa));
//        System.out.println(mainName(aa));
        LocalDateTime endTime = LocalDateTime.now().with(LocalTime.MIN);
        LocalDateTime startTime = endTime.minusDays(1);
        System.out.println(endTime);
        System.out.println(startTime);
        DateTimeFormatter formatterWithSeparator = DateTimeFormatter.ofPattern("yyyy年MM月dd日HH时");
        String formattedWithSeparator = endTime.format(formatterWithSeparator);
        System.out.println("带分隔符的格式: " + formattedWithSeparator);
    }
}
